using System.Collections.Generic;
using System.Linq;
using Sustainalytics.ESGRatings.BusinessLogic.Computing.Utils;
using Sustainalytics.ESGRatings.DataContract;

namespace Sustainalytics.ESGComputing.Service.Validators
{


    public class GovernanceDataSetValidator : Validator<GovernanceDataContainer>
    {
        public override ICollection<string> BrokenRules(GovernanceDataContainer entity)
        {
            if (entity.IndicatorTemplates.IsNullOrEmpty())
            {
                BrokenRulesList.Add("Invalid indicator list");
            }

            if (entity.Companies.IsNullOrEmpty())
            {
                BrokenRulesList.Add("Empty companies list");
            }

            if (entity.CompaniesRawScores.IsNullOrEmpty())
            {
                BrokenRulesList.Add("Empty raw scores list");
            }

            if (entity.Modifiers.IsNullOrEmpty())
            {
                BrokenRulesList.Add("Empty modifiers list");
            }

            if (entity.WeightMatrix == null)
            {
                BrokenRulesList.Add("Empty weight matrix");
            }
            else
            {
                if (entity.WeightMatrix.IssuesWeights.IsNullOrEmpty())
                {
                    BrokenRulesList.Add(
                        string.Format(
                            "Matrix with id {0} has no associated IssuesWeights",
                            entity.WeightMatrix.MatrixId));
                }

                if (entity.WeightMatrix.Matrix.IsNullOrEmpty())
                {
                    BrokenRulesList.Add(string.Format("Matrix with id {0} is invalid", entity.WeightMatrix.MatrixId));
                }

                if (entity.WeightMatrix.IssuesWeights.Any(issue => issue.Weights.IsNullOrEmpty()))
                {
                    BrokenRulesList.Add(
                        string.Format(
                            "Matrix with id {0} is invalid, because there are empty issue weights",
                            entity.WeightMatrix.MatrixId));
                }

                if (entity.WeightMatrix.Matrix.Any(issue => issue.IndicatorsData.IsNullOrEmpty()))
                {
                    BrokenRulesList.Add(
                        string.Format(
                            "Matrix with id {0} is invalid, because there are empty region weights",
                            entity.WeightMatrix.MatrixId));
                }
            }

            return BrokenRulesList;
        }
    }
}